define([
    "UtilDir/util",
    "UtilDir/tool",
    "UtilDir/combotree",
    "UtilDir/dialog",
    "UtilDir/searchBlock",
    "HomeDir/js/router",
    "HomeDir/js/tabs",
    'UtilDir/loading',
    "static/app/cupload",
    "EasyUI", "EasyUI-lang"
], function (Util, Tool, Combotree, Dialog, SearchBlock, Router, Tabs, Loading, cupload) {
    var newUpload
    var newUploadUrls
    var sysPath = getServer() + "/static/app/fwsjcj";
    var auditFormHtml = sysPath + "/censusdata/views/censusForm.html";
    var clearImageUrl = function () {
        newUploadUrls = '';
    };
    var getZwController = function () {
        return getServer() + "/fw/taskForm";
    };
    var getDivisionController = function () {
        return getServer() + "/platform/org/divisions/";
    };
    var getController = function () {
        return getServer() + "/fw/structure";
    };
    var toolbar = [{
        iconCls: 'fa fa-plus-circle',
        text: "批量审核",
        handler: function () {
            batchCheck();
        }
    }, {
        iconCls: 'fa fa-trash-o',
        text: "删除",
        handler: function () {
            deleteTask()
        }
    }];
    /**
     * 页面初始化
     */
    var init = function () {
        initSearchBlock();
        queryBtnBind();
        initDivision();
        initSearchForm();
        getUserState();
        Util.preventclick("taskName");
    };
// 获取用户角色信息，用于判断审核权限等..
    var userState = [];
    // 根据用户角色信息获取用户等级
    var userLv = '';
    var getUserState = function () {
        $.ajax({
            url: getController() + "/getRole",
            data: '',
            type: "GET",
            contentType: "application/json; charset=utf-8",
            success: function (data) {
                console.log(data)
                userState = data.roleName;
                setUserLv(data.roleName);
                if (userLv == 1 || userLv == 2 || userLv == 3) {
                    toolbar = [{
                        iconCls: 'fa fa-plus-circle',
                        text: "批量审核",
                        handler: function () {
                            batchCheck();
                        }
                    }, {
                        iconCls: 'fa fa-plus-circle',
                        text: "批量退回",
                        handler: function () {
                            batchBack();
                        }
                    }, {
                        iconCls: 'fa fa-trash-o',
                        text: "删除",
                        handler: function () {
                            deleteTask()
                        }
                    }, {
                        iconCls: 'fa fa-upload',
                        text: "批量导入",
                        handler: function () {
                            // 导出图片接口
                            importTask()
                        }
                    }];
                }
                createAuditGrid();
            }
        });
    }
    /**
     * 根据角色名称获取对应用户等级
     *
     * @param userState
     */
    var setUserLv = function (userState) {
        if (userState.indexOf("超级管理员") !== -1) {
            userLv = 1;
            console.log(888)
            return;
        }
        if (userState.indexOf("省级管理员") !== -1) {
            userLv = 2;
            return;
        }
        if (userState.indexOf("市级管理员") !== -1) {
            userLv = 3;
            return;
        }
    }
    var initSearchBlock = function () {
        SearchBlock.init("searchBlock");
    };
    // 列表查询
    var queryBtnBind = function () {
        // 查询按钮
        $("#btnSearch").click(function () {
            createAuditGrid();
        });
        // 重置按钮
        $("#btnReset").click(function () {
            $("#taskName").val("");
            $("#status").val("");
            $("#buildingType").val("");
            $("#collecPerson").val("");
            $("#buildingCode").val("");
            $("#buildingName").val("");
            resetDivision();
        });
        //导出
        $("#btnExport").click(function () {
            var buildingType = $("#buildingType").val();
            if(buildingType==""){
                Util.alert("每次只能导出一种建筑物类别的数据，请选择建筑物类别!");
            }else{
                var taskName=$("#taskName").val();
                var status=$("#status").val();
                var belongtoProvince=$("#belongtoProvince").val();
                var belongtoCity=$("#belongtoCity").val();
                var belongtoArea=$("#belongtoArea").val();
                var buildingCode=$("#buildingCode").val();
                var buildingName=$("#buildingName").val();
                var collecPerson=$("#collecPerson").val();
                if(status==null){
                    status="";
                }
                if(belongtoProvince==null){
                    belongtoProvince="";
                }
                if(belongtoCity==null){
                    belongtoCity="";
                }
                if(belongtoArea==null){
                    belongtoArea="";
                }


                $.ajax({
                    url: getZwController() + "/isEmpty",
                    data: {
                        taskName:taskName,
                        status:status,
                        buildingType:buildingType,
                        belongtoProvince:belongtoProvince,
                        belongtoCity:belongtoCity,
                        belongtoArea:belongtoArea,
                        buildingCode:buildingCode,
                        buildingName:buildingName,
                        collecPerson:collecPerson
                    },
                    type: "get",
                    success: function (data) {
                        if (data.message == '否') {
                            window.location.href = getZwController() + "/export" +
                                "?taskName=" + taskName+
                                "&status=" + status+
                                "&buildingType="+buildingType+
                                "&belongtoProvince=" + belongtoProvince+
                                "&belongtoCity=" + belongtoCity+
                                "&belongtoArea=" +  belongtoArea+
                                "&buildingCode=" + buildingCode+
                                "&buildingName=" + buildingName+
                                "&collecPerson=" + collecPerson;
                        }else {
                            Util.alert('该类型数据数据为空，无法导出！');
                        }
                    }
                });
            }
        });
    };
    var createAuditGrid = function () {
        console.log("7777")
        var opts1;
        $("#auditGrid").datagrid({
            url: getZwController() + "/getPage",
            method: "GET",
            fitColumns: true,
            autoRowHeight: false,
            nowrap: false,
            columns: [[
                {field: "ck", checkbox: true},
                {
                    field: 'myNo',
                    title: '序号',
                    align: 'center',
                    width: '4%',
                    formatter: function (value, row, index) {
                        if (!opts1) {
                            opts1 = $('#auditGrid').datagrid('options');
                        }
                        return opts1.pageSize * (opts1.pageNumber - 1) + index + 1;
                    }
                },
                {field: 'taskName', title: '所属任务', width: '20%', align: 'center'},
                {field: 'buildingCode', title: '建筑物编号', width: '10%', align: 'center'},
                {field: 'buildingAddress', title: '所属地区', width: '15%', align: 'center'},
                {
                    field: 'bulidingType', title: '建筑物类别', width: '8%', align: 'center',
                    formatter: function (value) {
                        if (value == 0) {
                            return '城镇住宅';
                        } else if (value == 1) {
                            return '城镇非住宅';
                        } else if (value == 2) {
                            return '农村住房';
                        } else if (value == 3) {
                            return '农村公共建筑';
                        }
                    }
                },
                {field: 'buildingName', title: '建筑物名称', width: '17%', align: 'center'},
                {
                    field: 'spType', title: '数据状态', width: '8%', align: 'center',
                    formatter: function (value) {
                        if (value == 0) {
                            return '未提交';
                        } else if (value == 1) {
                            return '未审核';
                        } else if (value == 2) {
                            return '审核未通过';
                        } else if (value == 3) {
                            return '审核通过';
                        }
                    }
                },
                {
                    field: 'dataSources', title: '数据来源', width: '8%', align: 'center',
                    formatter: function (value) {
                        if (value == 0) {
                            return 'app采集';
                        } else if (value == 1) {
                            return '批量导入';
                        }
                    }
                },
                {field: 'collecPerson', title: '数据采集人', width: '7%', align: 'center'},
                {
                    field: 'operation', title: '操作', width: '10%', align: 'center',
                    formatter: function (value, rowData, rowIndex) {
                        if (rowData.spType == 1 || rowData.spType == 2) {
                            if (rowData.dataSources == 0) {
                                if (rowData.backOpinion != null) {
                                    return '<a onclick="_check(\'' + rowData.formId + "','" + rowData.bulidingType + '\')">审核</a >&nbsp;&nbsp;<a onclick="_back(\'' + rowData.formId + "',2,'" + rowData.bulidingType + '\')">退回意见</a >&nbsp;&nbsp;&nbsp;&nbsp;&nbsp<a onclick="_view(\'' + rowData.formId + "','" + rowData.bulidingType + "','" + rowData.spType + '\')">查看表单</a >';
                                } else {
                                    return '<a onclick="_check(\'' + rowData.formId + "','" + rowData.bulidingType + '\')">审核</a >&nbsp;&nbsp;&nbsp;&nbsp;<a onclick="_view(\'' + rowData.formId + "','" + rowData.bulidingType + "','" + rowData.spType + '\')">查看表单</a >';
                                }
                            } else if (rowData.dataSources == 1) {
                                if (rowData.backOpinion != null) {
                                    return '<a onclick="_check(\'' + rowData.formId + "','" + rowData.bulidingType + '\')">审核</a >&nbsp;&nbsp;<a onclick="_back(\'' + rowData.formId + "',2,'" + rowData.bulidingType + '\')">退回意见</a >&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a onclick="_view(\'' + rowData.formId + "','" + rowData.bulidingType + "','" + rowData.spType + '\')">查看表单</a >';
                                } else {
                                    return '<a onclick="_check(\'' + rowData.formId + "','" + rowData.bulidingType + '\')">审核</a >&nbsp;&nbsp;&nbsp;&nbsp;<a onclick="_view(\'' + rowData.formId + "','" + rowData.bulidingType + "','" + rowData.spType + '\')">查看表单</a >';
                                }
                                // return '<a onclick="_check(\'' + rowData.formId + "','" + rowData.bulidingType + '\')">审核</a >&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a onclick="_upload(\'' + rowData.formId + "','" + rowData.bulidingType + '\')">上传图片</a >';
                            }
                        } else if (rowData.spType == 3) {
                            console.info(rowData.backOpinion)
                            if (rowData.backOpinion != null) {
                                return '<a onclick="_back(\'' + rowData.formId + "',1,'" + rowData.bulidingType + '\')">退回</a >&nbsp;&nbsp;<a onclick="_back(\'' + rowData.formId + "',2,'" + rowData.bulidingType + '\')">退回意见</a >&nbsp;&nbsp;&nbsp;&nbsp;<a onclick="_view(\'' + rowData.formId + "','" + rowData.bulidingType + "','" + rowData.spType + '\')">查看表单</a >';
                            } else {
                                return '<a onclick="_back(\'' + rowData.formId + "',1,'" + rowData.bulidingType + '\')">退回</a >&nbsp;&nbsp;&nbsp;&nbsp;<a onclick="_view(\'' + rowData.formId + "','" + rowData.bulidingType + '\')">查看表单</a >';
                            }
                        }

                    }
                },
            ]],
            toolbar: toolbar,
            queryParams: {
                /*region: $("#region").val(),*/
                taskName: $("#taskName").val(),
                status: $("#status").val(),
                buildingType: $("#buildingType").val(),
                collecPerson: $("#collecPerson").val(),
                buildingCode: $("#buildingCode").val(),
                belongtoProvince: $("#belongtoProvince").val(),
                belongtoCity: $("#belongtoCity").val(),
                belongtoArea: $("#belongtoArea").val(),
                buildingName: $("#buildingName").val()
            },
            pagination: true,
            pageSize: 10
        });
    };
    var reasonFormValidator = function () {
        $("#auditForm").validate({
            rules: {
                reason: {
                    required: true
                }

            },
            messages: {
                reason: {
                    required: "审核不通过原因不允许为空!"
                }

            }
        });
    }
    var formValidator = function () {
        $("#userForm").validate({
            rules: {
                buildingUpNum: {
                    required: true
                },
                buildingDown: {
                    required: true
                },
                bulidingType: {
                    required: true
                },
                buildingTime: {
                    required: true
                },
                belongtoProvince: {
                    required: true
                },
                houseNum: {
                    required: true
                },
                belongtoCity: {
                    required: true
                },
                presonNum: {
                    required: true
                },
                belongtoArea: {
                    required: true
                },
                oldFortificationIntensity: {
                    required: true
                },
                belongtoStreet: {
                    required: true
                },
                houseNumber: {
                    required: true
                },
                areaName: {
                    required: true
                },
                isSeismicReinforce: {
                    required: true
                },
                buildingName: {
                    required: true
                },
                buildingAddress: {
                    required: true
                },
                isDamage: {
                    required: true
                },
                structureTypeOther: {
                    required: true
                },
                buildingArea: {
                    required: true
                },
                result: {
                    required: true
                },
                oldFortificationType: {
                    required: true
                },
                belongtoTown: {
                    required: true
                },
                belongtoVillage: {
                    required: true
                },
                structureType: {
                    required: true
                },
                buildMethod: {
                    required: true
                },
                homesteadArea: {
                    required: true
                },
                buildingLayerNum: {
                    required: true
                },
                buildingNum: {
                    required: true
                },
                buildingHight: {
                    required: true
                },
                houseUseSituation: {
                    required: true
                },
                houseReinforceSituation: {
                    required: true
                },
                houseMeasures: {
                    required: true
                },
                houseDisasterSituation: {
                    required: true
                },
                buildingDamage: {
                    required: true
                },
                isAuxiliaryHouse: {
                    required: true
                },
                housePurposeOther: {
                    required: true
                }
            },
            messages: {
                housePurposeOther: {
                    required: "房屋用途不允许为空!"
                },
                buildingUpNum: {
                    required: "建筑地上层数不允许为空!"
                },
                buildingDown: {
                    required: "建筑地下层数不允许为空!"
                },
                bulidingType: {
                    required: "被调查建筑分类不允许为空!"
                },
                buildingTime: {
                    required: "建造时间不允许为空!"
                },
                belongtoProvince: {
                    required: "所属省份不允许为空!"
                },
                houseNum: {
                    required: "户数不允许为空!"
                },
                belongtoCity: {
                    required: "所属地级市不允许为空!"
                },
                presonNum: {
                    required: "人数不允许为空!"
                },
                belongtoArea: {
                    required: "所在区不允许为空!"
                },
                oldFortificationIntensity: {
                    required: "原设防烈度不允许为空!"
                },
                belongtoStreet: {
                    required: "所在路/街名不允许为空!"
                },
                houseNumber: {
                    required: "小区所在门牌号不允许为空!"
                },
                areaName: {
                    required: "小区名称不允许为空!"
                },
                isSeismicReinforce: {
                    required: "是否进行过抗震加固/抗震加固时间不允许为空!"
                },
                buildingName: {
                    required: "建筑名称不允许为空!"
                },
                buildingAddress: {
                    required: "建筑地址不允许为空!"
                },
                isDamage: {
                    required: "有无明显可见的裂缝、变形、倾斜等不允许为空!"
                },
                structureTypeOther: {
                    required: "结构类型不允许为空!"
                },
                buildingArea: {
                    required: "建筑面积不允许为空!"
                },
                result: {
                    required: "初步结论不允许为空!"
                },
                oldFortificationType: {
                    required: "原设防类别不允许为空!"
                },
                belongtoTown: {
                    required: "所在乡（镇）不允许为空!"
                },
                belongtoVillage: {
                    required: "所在行政村不允许为空!"
                },
                structureType: {
                    required: "结构类型不允许为空!"
                },
                buildMethod: {
                    required: "建造方式不允许为空!"
                },
                homesteadArea: {
                    required: "宅基地面积不允许为空!"
                },
                buildingLayerNum: {
                    required: "居住房屋建筑层数不允许为空!"
                },
                buildingNum: {
                    required: "居住房屋建筑间数不允许为空!"
                },
                buildingHight: {
                    required: "居住房屋建筑总高度不允许为空!"
                },
                houseUseSituation: {
                    required: "居住房屋使用情况不允许为空!"
                },
                houseReinforceSituation: {
                    required: "居住房屋抗震设防加固情况不允许为空!"
                },
                houseMeasures: {
                    required: "居住房屋抗震构造措施不允许为空!"
                },
                houseDisasterSituation: {
                    required: "居住房屋受灾情况不允许为空!"
                },
                buildingDamage: {
                    required: "有无明显可见的裂缝、变形、倾斜等不允许为空!"
                },
                isAuxiliaryHouse: {
                    required: "是否有辅助用房不允许为空!"
                }
            }
        });
    };

    // 批量审核
    var batchCheck = function () {
        var rows = $("#auditGrid").datagrid("getSelections");
        if (rows == null || rows.length == 0) {
            Util.alert("请选择一条数据!");
            return;
        }
        var formId;
        for (var i = 0; i < rows.length; i++) {
            if (i == 0) {
                formId = rows[i].fwId;
            } else {
                formId = formId + "," + rows[i].fwId;
            }
        }
        // 判断所选中的数据中的状态
        for (var j = 0; j < rows.length; j++) {
            if (rows[j].spType != 1) {
                Util.alert('所选数据中有不处于未审核状态的！');
                return;
            }
        }

        var slidebar = Util.slidebar({
            url: auditFormHtml,
            width: "580pauditFormHtmlx",
            cache: false,
            close: true,
            afterLoad: function () {
                $("#approved").on("click", function () {
                    $.ajax({
                        url: getZwController() + "/spAllForm",
                        data: JSON.stringify({
                            status: "3",
                            formId: formId
                        }),
                        type: "post",
                        contentType: "application/json; charset=utf-8",
                        success: function (data) {
                            debugger
                            Util.alert(data.message);
                            slidebar.close();
                            createAuditGrid();
                        }
                    });
                });
                $("#unapproved").on("click", function () {
                    var reason = $('#unapproval_reason').css('display');
                    if (reason == 'none') {
                        $('#unapproval_reason').show();
                    } else {
                        reasonFormValidator();
                        if ($("#auditForm").valid()) {
                            var reason = $('#reason').val();
                            debugger;
                            $.ajax({
                                url: getZwController() + "/spAllForm",
                                contentType: "application/json",
                                data: JSON.stringify({
                                    formId: formId,
                                    status: '2',
                                    reason: reason
                                }),
                                type: "post",
                                success: function (data) {
                                    Util.alert(data.message);
                                    slidebar.close();
                                    createAuditGrid();
                                }
                            });
                        }
                    }
                });
            }
        });
    };
    // 批量退回
    var batchBack = function () {
        var rows = $("#auditGrid").datagrid("getSelections");
        if (rows == null || rows.length == 0) {
            Util.alert("请选择一条数据!");
            return;
        }
        var formId;
        for (var i = 0; i < rows.length; i++) {
            if (i == 0) {
                formId = rows[i].fwId;
            } else {
                formId = formId + "," + rows[i].fwId;
            }
        }
        // 判断所选中的数据中的状态
        for (var j = 0; j < rows.length; j++) {
            if (rows[j].spType != 3) {
                Util.alert('所选数据中有不处于审核通过状态的！');
                return;
            }
        }
        var siftBackDataHtml = openBackPage();
        var slidebar = Util.slidebar({
            url: siftBackDataHtml,
            width: "600px",
            cache: false,
            close: true,
            afterLoad: function () {
                $("#back").on("click", function () {
                    var backMessage = $('#backOpinion').val();
                    formValidatorBack();
                    if ($('#auditForm').valid()) {
                        var backMessage = $('#backOpinion').val();
                        $.ajax({
                            url: getZwController() + "/batchBack/" + formId,
                            data: JSON.stringify({
                                backOpinion: backMessage
                            }),
                            type: "post",
                            contentType: "application/json; charset=utf-8",
                            success: function (data) {
                                Util.alert(data.message);
                                createAuditGrid();
                                slidebar.close();

                            }
                        });
                        /*slidebar.close();*/
                    }
                });
            }
        });
    };

    /*// 导出
    var exportTask = function () {
        var buttons = [];
        buttons.push({
            name: '确定',
            callback: function () {
                //点击确定
                var formType = $("#formType").val();
                let startDate = $("#complex1").val();
                let endDate = $("#complex2").val();
                debugger;
                $.ajax({
                    url: getZwController() + "/isEmpty",
                    data: {
                        type: formType,
                        startDate: startDate,
                        endDate: endDate
                    },
                    type: "get",
                    success: function (data) {
                        console.log(data);
                        if (data.message == '否') {
                            window.location.href = getZwController() + "/export?type=" + formType + "&startDate=" + startDate + "&endDate=" + endDate;
                        } else if (data.message == '是') {
                            Util.alert('该类型数据数据为空，无法导出！');
                        } else {
                            // 未选择类型，请选择一种类型！
                            Util.alert(data.message);
                        }
                    }
                });
                dialog.hide();
            }
        });
        var dialog = Dialog({
            id: "viewTeamDialog",
            cache: false,
            title: '选择表单类型', //dialog标题
            width: "400px",
            height: "250px",
            body:
                '<div id="TeamGrid">' +
                '<div class="col-md-12 form-horizontal">' +
                '<div class="form-group">' +
                '<label for="formType" class="col-md-4 control-label"> </span>表单类型:</label>' +
                '<div class="col-md-8">' +
                '<select class="form-control" id="formType" name="formType" >' +
                '<option value="" disabled selected style="display:none;">请选择</option>' +
                '<option value="0">城镇住宅</option>' +
                '<option value="1">城镇非住宅</option>' +
                '<option value="2">农村住房</option>' +
                '<option value="3">农村公共建筑</option>' +
                '</select>' +
                '</div>' +
                '</div>' +
                '<div class="form-group">' +
                '<label for="formType" class="col-md-4 control-label"> </span>开始日期:</label>' +
                '<div class="col-md-8">' +
                '<div class="input-group">' +
                '<input id="complex1" type="text" class="form-control">' +
                '<a id="complex_del1" class="input-group-addon"><i class="fa fa-times"></i></a>' +
                '<a id="complex_show1" class="input-group-addon"><i class="fa fa-calendar"></i></a>' +
                '</div>' +
                '</div>' +
                '</div>' +
                '<div class="form-group">' +
                '<label for="complex2" class="col-md-4 control-label"> </span>结束日期:</label>' +
                '<div class="col-md-8">' +
                '<div class="input-group">' +
                '<input id="complex2" type="text" class="form-control">' +
                '<a id="complex_del2" class="input-group-addon"><i class="fa fa-times"></i></a>' +
                '<a id="complex_show2" class="input-group-addon"><i class="fa fa-calendar"></i></a>' +
                '</div>' +
                '</div>' +
                '</div>' +
                '</div>' +
                '</div>',
            buttons: buttons,
            afterOpen: function () {
                dateComponent();
            }
        });
        dialog.show();
    }*/
    //批量导入
    window.importTask = function () {
        var buttons = [];
        buttons.push({
            name: '确定',
            callback: function () {
                var category = $("#templateSelect").val();
                if (category == null) {
                    Util.alert("请选择建筑物类别!");
                    return;
                }
                var rows = $("#taskGrid").datagrid("getSelections");
                if (rows == null || rows.length == 0) {
                    Util.alert("请分配任务!");
                    return;
                }
                uploadTask($("#templateSelect").val(), rows[0].taskName, rows[0].taskId);
                dialog.hide();
            }
        });
        var dialog = Dialog({
            id: "viewTeamDialog",
            cache: false,
            title: '选择建筑物类别并分配任务', //dialog标题
            width: "530px",
            height: "400px",
            body: '<div id="TeamGrid">' +
                '<div class="row">' +
                '<div class="col-md-12 form-horizontal">' +
                '<div class="form-group">' +
                '<label for="formType" class="col-md-3 control-label">建筑物类别:</label>' +
                '<div class="col-md-7">' +
                '<select class="form-control" id="templateSelect" name="templateSelect" >' +
                '<option value="" disabled selected style="display:none;">请选择</option>' +
                '<option value="0">城镇住宅</option>' +
                '<option value="1">城镇非住宅</option>' +
                '<option value="2">农村住房</option>' +
                '<option value="3">农村公共建筑</option>' +
                '</select>' +
                '</div>' +
                '</div>' +
                '</div>' +
                '</div>' +

                '<div class="row">' +
                '<div class="col-md-12 form-horizontal">' +
                '<div class="form-group">' +
                '<label for="tName" class="col-md-3 control-label">任务名称:</label>' +
                '<div class="col-md-7">' +
                '<input class="form-control" id="tName" value="" />' +
                '</div>' +
                '<div class="col-md-2">' +
                '<button id="query" class="btn btn-default" type="button">查询</button>' +
                '</div>' +
                '</div>' +
                '</div>' +
                '</div>' +

                '<div class="row">' +
                '<div id="taskGrid" style="width: 100%;"></div>' +
                '</div>' +
                '</div>' +

                '</div>',
            buttons: buttons,
            afterOpen: function () {
                createTaskGrid();
            }
        });
        dialog.show();

        //查询
        $("#query").click(function () {
            createTaskGrid();
        })

    };
    var createTaskGrid = function () {
        var opts1;
        $("#taskGrid").datagrid({
            url: getServer() + "/fw/task/page/0",
            method: "GET",
            nowrap: false,
            singleSelect: true,
            columns: [[
                {field: "ck", checkbox: true},
                {
                    field: 'myNo',
                    title: '序号',
                    align: 'center',
                    width: '9%',
                    formatter: function (value, row, index) {
                        if (!opts1) {
                            opts1 = $('#auditGrid').datagrid('options');
                        }
                        return opts1.pageSize * (opts1.pageNumber - 1) + index + 1;
                    }
                },
                {field: 'taskName', title: '任务名称', width: '30%', align: 'center'},
                {field: 'groupName', title: '承担小组', width: '30%', align: 'center'},
                {field: 'groupLeader', title: '组长', width: '30%', align: 'center'},
            ]],
            queryParams: {
                taskName: $("#tName").val(),
            },
            pagination: true,
            pageSize: 10
        });
    };


    var uploadTask = function (type, taskName, taskId) {

        var url;
        if (type == 0) {
            url = getServer() + "/static/excel/城镇住宅.xlsx";
        } else if (type == 1) {
            url = getServer() + "/static/excel/城镇非住宅.xlsx";
        } else if (type == 2) {
            url = getServer() + "/static/excel/农村住房.xlsx";
        } else if (type == 3) {
            url = getServer() + "/static/excel/农村公共建筑.xlsx";
        }
        $("#uploadModal").modal();
        $("#uploadModal").on("shown.bs.modal", function () {
            $("#downloadZwExcelTemplate").attr("href", url);
        });
        $('#uploadButton').off("click");
        $("#uploadButton").on("click", function () {
            var uploadinput = document.getElementById("uploadFile");
            if (uploadinput.value == "") {
                Util.alert("上传前请先选择文件!");
                return;
            }
            var formData = new FormData();
            formData.append("file", uploadinput.files[0]);
            formData.append("taskName", taskName);
            formData.append("taskId", taskId);
            $.ajax({
                url: getZwController() + `/importTask/${type}`,
                data: formData,
                processData: false, //因为data值是FormData对象，不需要对数据做处理。
                contentType: false,
                type: "POST",
                success: function (data) {
                    $("#uploadModal").modal('hide');
                    Util.alert(data);
                    createAuditGrid();
                }
            });
        });
    };
    /*// 导出多个图片为zip格式
    var exportPicture = function () {
        var buttons = [];
        buttons.push({
            name: '确定',
            callback: function () {
                //点击确定
                var formType = $("#formType").val();
                let startDate = $("#complex1").val();
                let endDate = $("#complex2").val();
                let province = $("#province").val();
                debugger;
                $.ajax({
                    url: getZwController() + "/isEmpty",
                    data: {
                        type: formType,
                        startDate: startDate,
                        endDate: endDate,
                        province: province
                    },
                    type: "get",
                    success: function (data) {
                        console.log(data);
                        if (data.message == '否') {
                            window.location.href = getZwController() + "/downLoadZipFile?type="+formType+"&startDate="+startDate+"&endDate="+endDate+"&province="+province;
                        } else if (data.message == '是') {
                            Util.alert('该类型数据数据为空，无法导出！');
                        } else {
                            // 未选择类型，请选择一种类型！
                            Util.alert(data.message);
                        }
                    }
                });
                dialog.hide();
            }
        });
        var dialog = Dialog({
            id: "viewTeamDialog",
            cache: false,
            title: '选择表单类型', //dialog标题
            width: "400px",
            height: "250px",
            body:
                '<div id="TeamGrid">' +
                '<div class="col-md-12 form-horizontal">' +
                '<div class="form-group">' +
                '<label for="formType" class="col-md-4 control-label"> </span>表单类型:</label>' +
                '<div class="col-md-8">' +
                '<select class="form-control" id="formType" name="formType" >' +
                '<option value="" disabled selected style="display:none;">请选择</option>' +
                '<option value="0">城镇住宅</option>' +
                '<option value="1">城镇非住宅</option>' +
                '<option value="2">农村住房</option>' +
                '<option value="3">农村公共建筑</option>' +
                '</select>' +
                '</div>' +
                '</div>' +

                '<div class="form-group">' +
                '<label for="formType" class="col-md-4 control-label"> </span>开始日期:</label>' +
                '<div class="col-md-8">' +
                '<div class="input-group">'+
                '<input id="complex1" type="text" class="form-control">'+
                '<a id="complex_del1" class="input-group-addon"><i class="fa fa-times"></i></a>'+
                '<a id="complex_show1" class="input-group-addon"><i class="fa fa-calendar"></i></a>'+
                '</div>'+
                '</div>' +
                '</div>' +
                '<div class="form-group">' +
                '<label for="complex2" class="col-md-4 control-label"> </span>结束日期:</label>' +
                    '<div class="col-md-8">' +
                        '<div class="input-group">'+
                            '<input id="complex2" type="text" class="form-control">'+
                            '<a id="complex_del2" class="input-group-addon"><i class="fa fa-times"></i></a>'+
                            '<a id="complex_show2" class="input-group-addon"><i class="fa fa-calendar"></i></a>'+
                        '</div>'+
                    '</div>' +
                '</div>' +
                '<div class="form-group">' +
                '<label for="province" class="col-md-4 control-label"> </span>省份:</label>' +
                    '<div class="col-md-8">' +
                    '<select class="form-control" id="province" name="province" >' +
                        '<option value="" selected style="display:none;">请选择</option>' +
                    '</select>' +
                    '</div>' +
                '</div>' +

                '</div>' +
                '</div>',
            buttons: buttons,
            afterOpen: function () {
                // 日期组件
                dateComponent();
                onlyProvince()
            }
        });
        dialog.show();
    }
    // 导出图片-省控件
    var onlyProvince = function () {
        $.ajax({
            url: getServer() + "/fw/taskForm/user/division",
            contentType: "application/json",
            type: "get",
            success: function (data) {
                if (data.message == '超级管理员') {
                    let html = "";
                    $.ajax({
                        url: "/app/divisions/root/subdivisions",
                        contentType: "application/json",
                        type: "get",
                        success: function (data) {
                            console.log(data);
                            $.each(data, function (idx, item) {
                                html += "<option value='" + item.divisionName + "' exid='" + item.divisionId + "'>" + item.divisionName + "</option>";
                            });
                            $("#province").append(html);
                        }
                    });
                } else {
                    var html = "<option value='" + data.divisionName + "' exid='" + data.divisionId + "'>" + data.divisionName + "</option>";
                    $("#province").append(html);
                    let divisionName = data.divisionName;
                    $("#province").val(divisionName);
                    $("#province").attr("disabled", true);
                }
            }
        });
    }*/

    // 日期组件
    var dateComponent = function () {
        require(["jquery", "Date", "DateCN", "css!DateCss"], function ($) {
            $("#complex1").datetimepicker({
                //设置使用语言：cn是自定义的中文版本，还可以扩展其他语言版本
                language: "cn",
                //输出格式化
                format: 'yyyy-mm-dd',
                //直接选择‘今天’
                todayBtn: true,
                //设置最精确的时间选择视图
                minView: 'month',
                //高亮当天日期
                todayHighlight: true,
                //选择完毕后自动关闭
                autoclose: true
            });
            /* 删除按钮 */
            $("#complex_show1").on("click", function () {
                $('#complex1').datetimepicker('show');
            });
            /* 显示按钮 */
            $("#complex_del1").on("click", function () {
                $("#complex1").val("");
            });

            $("#complex2").datetimepicker({
                //设置使用语言：cn是自定义的中文版本，还可以扩展其他语言版本
                language: "cn",
                //输出格式化
                format: 'yyyy-mm-dd',
                //直接选择‘今天’
                todayBtn: true,
                //设置最精确的时间选择视图
                minView: 'month',
                //高亮当天日期
                todayHighlight: true,
                //选择完毕后自动关闭
                autoclose: true
            });
            /* 删除按钮 */
            $("#complex_show2").on("click", function () {
                $('#complex2').datetimepicker('show');
            });
            /* 显示按钮 */
            $("#complex_del2").on("click", function () {
                $("#complex2").val("");
            });
            // 时间大小规则
            $("#complex1").change(function () {
                if ($("#complex1").val() != "" && $("#complex2").val() != "") {
                    if ($("#complex1").val() > $("#complex2").val()) {
                        Util.alert("开始日期必须小于等于结束日期", function () {
                            $("#complex1").val("");
                            $("#complex2").val("");
                        });
                        return;
                    }
                }
            });
            $("#complex2").change(function () {
                if ($("#complex1").val() != "" && $("#complex2").val() != "") {
                    if ($("#complex1").val() > $("#complex2").val()) {
                        Util.alert("开始日期必须小于等于结束日期", function () {
                            $("#complex1").val("");
                            $("#complex2").val("");
                        });
                        return;
                    }
                }
            });
        })
    }
    // 删除
    var deleteTask = function () {
        var rows = $("#auditGrid").datagrid("getSelections");
        if (rows == null || rows.length == 0) {
            Util.alert("请选择一行数据!");
            return;
        } else if (rows[0].spType != '1') {
            Util.alert("数据状态为未审核的才能删除!");
            return;
        } else if (rows.length >= 1) {
            for (let i = 0; i < rows.length; i++) {
                if (rows[i].spType != '1') {
                    Util.alert("数据状态为未审核的才能删除!");
                    return;
                }
            }
        }
        Util.confirm("是否要删除选中的表单?", function () {
            var ids = "";
            $.each(rows, function (i, row) {
                ids += row.fwId + ",";
            });
            ids = ids.substr(0, ids.length - 1);
            $.ajax({
                url: getServer() + "/fw/taskForm/del",
                contentType: "application/json",
                data: ids,
                type: "post",
                success: function (data) {
                    Util.alert(data.message);
                    createAuditGrid();
                }
            });
        }, function () {
            return;
        });
    }
    // 查看表单
    window._view = function (formId, category, status) {
        debugger;
        // var censusDataHtml = sysPath + "/censusdata/views/censusForm_city.html";
        var censusDataHtml = openForm(category);
        var slidebar = Util.slidebar({
            url: censusDataHtml,
            width: "900px",
            cache: false,
            close: true,
            afterLoad: function () {
                getData(formId, category, status);
                // getRole(roleId);
            }
        });
    };
//图片上传
    window._upload = function (formId, type) {
        var uploadData = {};
        var flag = true;
        $.ajax({
            url: getZwController() + "/findById",
            data: {
                type: type,
                formId: formId
            },
            type: "get",
            success: function (data) {
                uploadData = data
                if (data.image) {
                    console.log(data.image)
                    console.log(data.image.split(","))
                    newUpload = new Cupload({
                        ele: '#cupload',
                        num: 99,
                        data: data.image.split(",")
                    })
                    newUploadUrls = data.image
                } else {
                    newUpload = new Cupload({
                        ele: '#cupload',
                        num: 99
                    })
                    newUploadUrls = ''
                }
                var cuploadBtn = document.getElementById('cuploadBtn')
                cuploadBtn.addEventListener('click', function () {
                    flag = false;
                    var loading = Loading({
                        text: "正在加载"
                    });
                    var base64Info = newUpload.imageArr;
                    console.log(base64Info)
                    var buildingCode = data.buildingCode;
                    console.log(buildingCode)
                    var imageOk = true
                    for (let i = 0; i < base64Info.length; i++) {
                        if (base64Info[i] && !/^http/.test(base64Info[i])) {
                            const item = base64Info[i];
                            console.log(item)
                            // console.log(/^data:image\/(jpg|png|gif|jpeg);base64/.test(item))
                            if (!/^data:image\/(jpg|png|gif|jpeg);base64/.test(item)) {
                                Util.alert('图片格式不支持，上传失败')
                                imageOk = false
                                return
                            }
                        }
                    }
                    if (imageOk) {
                        loading.show();
                        $.ajax({
                            url: getZwController() + "/image64?buildingCode=" + buildingCode,
                            data: JSON.stringify(base64Info),
                            type: "post",
                            contentType: "application/json; charset=utf-8",
                            success: function (data) {
                                console.log(data)
                                if (!data) {
                                    setTimeout(function () {
                                        loading.close();
                                        Util.alert('上传失败')
                                    }, 3000);
                                    return
                                }
                                for (let i = 0; i < data.length; i++) {
                                    const item = data[i];
                                    if (!/^.*(jpg|png|gif|jpeg)$/.test(item)) {
                                        Util.alert('图片格式错误，上传失败')
                                        return
                                    }
                                }
                                for (let i = 0; i < data.length; i++) {
                                    const item = data[i];
                                    // console.log(/恶意程序/.test(item))
                                    if (/恶意程序/.test(item)) {
                                        Util.alert('图片上传错误，请重试')
                                        return
                                    }
                                }
                                newUploadUrls = data.join(',')
                                setTimeout(function () {
                                    loading.close();
                                    Util.alert('图片已上传，请点击确定保存图片')
                                }, 3000);
                            },
                            error: function () {
                                setTimeout(function () {
                                    loading.close();
                                    Util.alert('上传失败')
                                }, 3000);
                            }
                        });
                    }
                })
            }

        });
        var url;
        //为弹出框增加操作按钮
        var buttons = [];
        buttons.push({
            name: "确定",
            callback: function () {
                if (flag) {
                    Util.alert('请先上传图片');
                } else {
                    uploadData.image = newUploadUrls
                    if (type == 0) {
                        debugger;
                        url = getServer() + "/fw/task/cityTask";
                    } else if (type == 1) {
                        url = getServer() + "/fw/task/noCityTask";
                    } else if (type == 2) {
                        url = getServer() + "/fw/task/villageHouse";
                    } else if (type == 3) {
                        url = getServer() + "/fw/task/villagePubHouse";
                    }
                    $.ajax({
                        url: url + "/update",
                        contentType: "application/json",
                        data: JSON.stringify(uploadData),
                        type: "post",
                        success: function (data) {
                            console.log(data)
                            Util.alert('保存成功');
                            clearImageUrl();
                        }
                    });
                }

            }
        });
        var dialog = Dialog({
            id: "BaseDialog",
            title: "上传图片",
            width: "600px",
            height: "300px",
            dialogSize: "", //modal-lg或modal-sm
            body: `   <div class="row" style='margin:20px'>
                        <span class="requird">*</span>竣工验收照片:
                         <div style='display: flex;justify-content: center;'>
                            <button class="btn btn-success" id='cuploadBtn'>上传</button>
                        </div>
                        <div>
                            <div id="cupload" style='display: flex;flex-direction: column; align-items: center'></div>
                        </div>
                       
                    </div>`,
            buttons: buttons
        });
    };
    //打开退回页面
    var openBackPage = function () {
        return sysPath + "/censusdata/views/backPage.html";
    }
    //退回
    window._back = function (formId, flag, bulidingType) {
        console.log(formId + "---" + flag + "--" + bulidingType)
        var backOpinion;
        $.ajax({
            url: getZwController() + "/getChild/" + formId,
            type: "get",
            success: function (data) {
                console.log(data);
                backOpinion = data;
                var siftBackDataHtml = openBackPage();
                var slidebar = Util.slidebar({
                    url: siftBackDataHtml,
                    width: "600px",
                    cache: false,
                    close: true,
                    afterLoad: function () {
                        console.info(flag);
                        if (flag == 2) {
                            $("#backOpinion").text(backOpinion);
                            $("#back").css("display", "none");
                        }

                        $("#back").on("click", function () {
                            var backMessage = $('#backOpinion').val();
                            formValidatorBack();
                            if ($('#auditForm').valid()) {
                                $.ajax({
                                    url: getZwController() + "/back/" + formId,
                                    data: JSON.stringify({
                                        backOpinion: backMessage
                                    }),
                                    type: "post",
                                    contentType: "application/json; charset=utf-8",
                                    success: function (data) {
                                        Util.alert(data.message);
                                        slidebar.close();
                                        //createAuditGrid();
                                        createAuditGrid($('#province').combobox('getText'), $('#city').combobox('getText'), $('#county').combobox('getText'));
                                    }
                                });
                            }
                        });
                    }
                });

            }
        })

    };
    //退回
    var formValidatorBack = function () {
        $("#auditForm").validate({
            rules: {
                backOpinion: {
                    required: true
                }
            },
            messages: {
                backOpinion: {
                    required: "退回原因不允许为空!"
                }
            }
        });
    };
    // 审核
    window._check = function (formId, category) {
        // var censusCheckDataHtml = sysPath + "/censusdata/views/censusCheckForm_city.html";
        var rowData = JSON.stringify(rowData);
        var path;
        if (category == '0') {
            path = "spCity";
        } else if (category == '1') {
            path = "spNoCity";
        } else if (category == '2') {
            path = "spVillage";
        } else if (category == '3') {
            path = "spVillagePub";
        }
        console.info(path);
        var censusCheckDataHtml = openCheckForm(category);
        var slidebar = Util.slidebar({
            url: censusCheckDataHtml,
            width: "900px",
            cache: false,
            close: true,
            afterLoad: function () {
                formValidator();
                getData(formId, category);
                $("#approved").on("click", function () {
                    if ($('#userForm').valid()) {
                        var fwdata = Tool.serialize("userForm");
                        fwdata.spType = "3";
                        fwdata.fwId = formId;
                        $.ajax({
                            url: getZwController() + "/spForm/" + path,
                            data: JSON.stringify(fwdata),
                            type: "post",
                            contentType: "application/json; charset=utf-8",
                            success: function (data) {
                                debugger
                                Util.alert(data.message);
                                slidebar.close();
                                createAuditGrid();
                            }
                        });
                    }
                });
                $("#unapproved").on("click", function () {
                    if ($('#userForm').valid()) {
                        var reason = $('#unapproval_reason').css('display');
                        if (reason == 'none') {
                            $('#unapproval_reason').show();
                        } else {
                            reasonFormValidator();
                            if ($('#auditForm').valid()) {
                                var fwdata = Tool.serialize("userForm");
                                fwdata.spType = "2";
                                fwdata.reason = $('#reason').val();
                                fwdata.fwId = formId;
                                $.ajax({
                                    url: getZwController() + "/spForm/" + path,
                                    data: JSON.stringify(fwdata),
                                    type: "post",
                                    contentType: "application/json; charset=utf-8",
                                    success: function (data) {
                                        debugger
                                        $('#unapproval_reason').hide();
                                        Util.alert(data.message);
                                        slidebar.close();
                                        createAuditGrid();
                                    }
                                });
                            }
                        }
                    }

                });
            }
        });
    };

    // 查看获取数据
    var getData = function (id, type, status) {
        debugger;
        $.ajax({
            url: getZwController() + "/findById",
            data: {
                type: type,
                formId: id
            },
            type: "get",
            success: function (data) {
//          	console.log(data)
                Tool.deserialize("userForm", data);
                if (status == 2) {
                    $('#unapproval_reason').show();
                    $("#reason").val(data.reason);
                }
                if (data.image) {
                    var imageURL = data.image.split(",");
                    console.log(imageURL);
                    var html = "";
                    for (var i = 0; i < imageURL.length; i++) {
                        html += '<div class="col-md-12 has-feedback" style="padding-top: 7px;display: flex;justify-content: center;">' +
                            '<img src=' + imageURL[i] + ' alt="暂无图片" id="+image[i]+" name="+image[i]+" style="width: 400px;height: 533px;border: 1px solid #ddd;"/>' +
                            '</div>'
                    }
                    $("#imgparent").append(html);
                } else {
                    var html = "";
                    html += '<div class="col-md-12 has-feedback" style="padding-top: 7px;display: flex;justify-content: center;">' +
                        '<img src="" alt="暂无图片" id="image" name="image" style="width: 400px;height: 533px;border: 1px solid #ddd;"/>' +
                        '</div>'
                    $("#imgparent").append(html);
                }
                if (data.propertyNature == '其它') {
                    $('#propertyNatureOther').css('display', 'block');
                }
                if (data.housePurpose == '其它' || data.housePurpose == '其它集体公共建筑' || data.housePurpose == '开发性生产经营用房') {
                    $('#housePurposeOther').css('display', 'block');
                }
                if (data.structureType == '其它') {
                    $('#structureTypeOther').css('display', 'block');
                }
                /*if (data.image != '') {
                    $('#image').attr('src', data.image);
                }*/
                if (data.buildMethod == '其它') {
                    $('#buildMethodOther').css('display', 'block');
                }
                /* if(data.buildingIsDamage=='不确定'){
                     $('#buildingDamageRemark').css('display','block');
                 }*/
                //农村住宅辅助用房用途其它
                if (data.auxiliaryHousePurpose == '其它') {
                    $('#auxiliaryHousePurposeOther').css('display', 'block');
                }
                //农村住宅辅助用房构造方式其它
                if (data.auxiliaryHouseBuildMethod == '其它') {
                    $('#auxiliaryHouseBuildMethodOther').css('display', 'block');
                }
                //农村住宅居住房屋抗震构造措施情况其它
                if (data.houseMeasuresSituation == '其他抗震措施') {
                    $('#houseMeasuresSituationOther').css('display', 'block');
                }
                //农村住宅居住房屋抗震构造措施情况其它
                if (data.houseUseSituation == '其它') {
                    $('#houseUseSituationOther').css('display', 'block');
                }
                //农村住宅辅助用房结构其它
                if (data.auxiliaryHouseStructure == '其它') {
                    $('#auxiliaryHouseStructureOther').css('display', 'block');
                }
            }
        });
    }

    // 判断打开那个表单--查看表单
    var openForm = function (type) {
        var openform;
        if (type == '0') {
            // 城镇住宅
            openform = sysPath + "/censusdata/views/censusForm_city.html";
        } else if (type == '1') {
            // 城镇非住宅
            openform = sysPath + "/censusdata/views/censusForm_uncity.html";
        } else if (type == '2') {
            // 农村住房
            openform = sysPath + "/censusdata/views/censusForm_rural.html";
        } else if (type == '3') {
            // 农村公共建筑
            openform = sysPath + "/censusdata/views/censusForm_publicrural.html";
        }
        return openform;
    }

    // 判断打开那个表单--审核
    var openCheckForm = function (type) {
        var opencheckform;
        if (type == '0') {
            // 城镇住宅
            opencheckform = sysPath + "/censusdata/views/censusCheckForm_city.html";
        } else if (type == '1') {
            // 城镇非住宅
            opencheckform = sysPath + "/censusdata/views/censusCheckForm_uncity.html";
        } else if (type == '2') {
            // 农村住房
            opencheckform = sysPath + "/censusdata/views/censusCheckForm_rural.html";
        } else if (type == '3') {
            // 农村公共建筑
            opencheckform = sysPath + "/censusdata/views/censusCheckForm_publicrural.html";
        }
        return opencheckform;
    }

    // 初始化加载搜索框内容
    var initSearchForm = function () {
        //初始化行政岗区划
        var combotree = Combotree({
            // combo组件相关配置
            combo: {
                //要渲染的input的id
                id: "region",
                //下拉框的类型：单选or多选
                multi: false,
                key: {
                    idKey: "divisionId",
                    textKey: "divisionName"
                },
                //          placeholder: "请选择……",
                event: {
                    onShowPanel: function () {
                        console.log("show");
                    },
                    onHidePanel: function () {
                        console.log("hide");
                    },
                    onChange: function (n, o) {
                        debugger;
                        $("#regionId").val(n[0].divisionId);
                        $("#region").val(n[0].divisionName);
                    }
                }
            },
            // ztree组件相关配置
            ztree: {
                data: {
                    simpleData: {
                        enable: true,
                        idKey: "divisionId", // 主键属性名
                        pIdKey: "parentId" // 父节点属性名
                    },
                    key: {
                        name: "divisionName" // 显示名称属性名
                    }
                },
                check: {
                    chkboxType: {
                        'Y': '',
                        'N': ''
                    }
                }
            },
            data: {
                url: getDivisionController() + 'initDivisionZtree',
                type: 'GET',
                success: function () {

                }
            },
            formatter: function (node) {
                node.open = true;
            },
            value: $("#divisionId").val(),
            search: {
                enable: true,
                fields: ["divisionName"]
            }
        });
    }

    // 超级管理员-省市县
    var province = function () {
        var html = "";
        $.ajax({
            url: "/app/divisions/root/subdivisions",
            contentType: "application/json",
            type: "get",
            success: function (data) {
                console.log(data);
                $.each(data, function (idx, item) {
                    html += "<option value='" + item.divisionName + "' exid='" + item.divisionId + "'>" + item.divisionName + "</option>";
                });
                $("#belongtoProvince").append(html);
            }
        });
        // 点击省
        $("#belongtoProvince").change(function () {
            let divisionId = $(this).find("option:selected").attr("exid");
            let divisionName = $(this).find("option:selected").attr("value");

            var html = '<option value="" disabled selected style="display:none;">请选择</option>';
            $("#belongtoCity option").remove();
            $("#belongtoCity").append(html);
            $("#belongtoArea option").remove();
            $("#belongtoArea").append(html);
            console.log(divisionId);
            console.log(divisionName);
            if ($(this).val() == "北京市" || $(this).val() == "天津市" || $(this).val() == "上海市" || $(this).val() == "重庆市") {
                $("#belongtoCity").append("<option value='" + $(this).val() + "' exid='" + divisionId + "'>" + $(this).val() + "</option>");
                // 若是直辖市，直接退出此函数
                return;
            }
            $.ajax({
                url: "/app/divisions/" + divisionId + "/subdivisions",
                contentType: "application/json",
                type: "get",
                success: function (data) {
                    $.each(data, function (idx, item) {
                        html += "<option value='" + item.divisionName + "' exid='" + item.divisionId + "'>" + item.divisionName + "</option>";
                    });
                    $("#belongtoCity").append(html);
                }
            });
        });
        // 点击市
        $("#belongtoCity").change(function () {
            if ($(this).val() == "") return;
            var html = '<option value="" disabled selected style="display:none;">请选择</option>';
            $("#belongtoArea option").remove();
            $("#belongtoArea").append(html);
            var divisionId = $(this).find("option:selected").attr("exid");
            $.ajax({
                url: "/app/divisions/" + divisionId + "/subdivisions",
                contentType: "application/json",
                type: "get",
                success: function (data) {
                    $.each(data, function (idx, item) {
                        html += "<option value='" + item.divisionName + "' exid='" + item.divisionId + "'>" + item.divisionName + "</option>";
                    });
                    $("#belongtoArea").append(html);
                }
            });
        });
    }

    // 重置省市县
    var resetDivision = function () {
        let html = '<option value="" disabled selected style="display:none;">请选择</option>';
        $("#belongtoProvince").val("");
        $("#belongtoCity").html(html);
        $("#belongtoArea").html(html);
    }


    // 初始化搜索栏省市区
    var initDivision = function () {
        $.ajax({
            url: getServer() + "/fw/taskForm/user/division",
            contentType: "application/json",
            type: "get",
            success: function (data) {
                debugger;
                if (data.message == '超级管理员') {
                    province();
                } else {
                    var html = "<option value='" + data.divisionName + "' exid='" + data.divisionId + "'>" + data.divisionName + "</option>";
                    $("#belongtoProvince").append(html);

                    // 点击省
                    $("#belongtoProvince").change(function () {
                        let divisionId = $(this).find("option:selected").attr("exid");
                        let divisionName = $(this).find("option:selected").attr("value");

                        var html = '<option value="" disabled selected style="display:none;">请选择</option>';
                        $("#belongtoCity option").remove();
                        $("#belongtoCity").append(html);
                        console.log(divisionId);
                        console.log(divisionName);
                        if ($(this).val() == "北京市" || $(this).val() == "天津市" || $(this).val() == "上海市" || $(this).val() == "重庆市") {
                            $("#belongtoCity").append("<option value='" + $(this).val() + "' exid='" + divisionId + "'>" + $(this).val() + "</option>");
                            // 若是直辖市，直接退出此函数
                            return;
                        }
                        $.ajax({
                            url: "/app/divisions/" + divisionId + "/subdivisions",
                            contentType: "application/json",
                            type: "get",
                            success: function (data) {
                                $.each(data, function (idx, item) {
                                    html += "<option value='" + item.divisionName + "' exid='" + item.divisionId + "'>" + item.divisionName + "</option>";
                                });
                                $("#belongtoCity").append(html);
                            }
                        });
                    });
                    // 点击市
                    $("#belongtoCity").change(function () {
                        if ($(this).val() == "") return;
                        var html = '<option value="" disabled selected style="display:none;">请选择</option>';
                        $("#belongtoArea option").remove();
                        $("#belongtoArea").append(html);
                        var divisionId = $(this).find("option:selected").attr("exid");
                        $.ajax({
                            url: "/app/divisions/" + divisionId + "/subdivisions",
                            contentType: "application/json",
                            type: "get",
                            success: function (data) {
                                $.each(data, function (idx, item) {
                                    html += "<option value='" + item.divisionName + "' exid='" + item.divisionId + "'>" + item.divisionName + "</option>";
                                });
                                $("#belongtoArea").append(html);
                            }
                        });
                    });

                }
            }
        });
    }


    return {
        init: init
    };
});
